package com.ruoyi.law.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.law.domain.ContentExtend;
import com.ruoyi.law.service.IContentExtendService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 字段名选项扩展Controller
 * 
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/option/extend")
public class ContentExtendController extends BaseController
{
    @Autowired
    private IContentExtendService contentExtendService;

    /**
     * 查询字段名选项扩展列表
     */
    @PreAuthorize("@ss.hasPermi('option:extend:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContentExtend contentExtend)
    {
        startPage();
        List<ContentExtend> list = contentExtendService.selectContentExtendList(contentExtend);
        return getDataTable(list);
    }

    /**
     * 导出字段名选项扩展列表
     */
    @PreAuthorize("@ss.hasPermi('option:extend:export')")
    @Log(title = "字段名选项扩展", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContentExtend contentExtend)
    {
        List<ContentExtend> list = contentExtendService.selectContentExtendList(contentExtend);
        ExcelUtil<ContentExtend> util = new ExcelUtil<ContentExtend>(ContentExtend.class);
        util.exportExcel(response, list, "字段名选项扩展数据");
    }

    /**
     * 获取字段名选项扩展详细信息
     */
    @PreAuthorize("@ss.hasPermi('option:extend:query')")
    @GetMapping(value = "/{extendId}")
    public AjaxResult getInfo(@PathVariable("extendId") Long extendId)
    {
        return success(contentExtendService.selectContentExtendByExtendId(extendId));
    }

    /**
     * 新增字段名选项扩展
     */
    @PreAuthorize("@ss.hasPermi('option:extend:add')")
    @Log(title = "字段名选项扩展", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContentExtend contentExtend)
    {
        return toAjax(contentExtendService.insertContentExtend(contentExtend));
    }

    /**
     * 修改字段名选项扩展
     */
    @PreAuthorize("@ss.hasPermi('option:extend:edit')")
    @Log(title = "字段名选项扩展", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContentExtend contentExtend)
    {
        return toAjax(contentExtendService.updateContentExtend(contentExtend));
    }

    /**
     * 删除字段名选项扩展
     */
    @PreAuthorize("@ss.hasPermi('option:extend:remove')")
    @Log(title = "字段名选项扩展", businessType = BusinessType.DELETE)
	@DeleteMapping("/{extendIds}")
    public AjaxResult remove(@PathVariable Long[] extendIds)
    {
        return toAjax(contentExtendService.deleteContentExtendByExtendIds(extendIds));
    }
}
